package com.openlogic.flow.mapstruct;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.dozer.Mapper;
import org.dromara.warm.flow.orm.entity.FlowDefinition;
import org.noear.solon.annotation.Component;

import com.openlogic.common.core.mapstruct.EntityMapper;
import com.openlogic.flow.domain.dto.FlowDefinitionDto;
import com.openlogic.flow.domain.vo.FlowDefinitionVo;

@Component
public class FlowDefinitionMapStruct implements EntityMapper<FlowDefinitionDto, FlowDefinition, FlowDefinitionVo> {

	/**
     * dozer转换的核心mapper对象
     */
    public static final Mapper converter = new org.dozer.DozerBeanMapper();

	@Override
	public FlowDefinitionDto toDTO(FlowDefinition e) {
		return converter.map(e, FlowDefinitionDto.class);
	}

	@Override
	public List<FlowDefinitionDto> toDTO(List<FlowDefinition> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, FlowDefinitionDto.class))
		        .collect(Collectors.toList());	
	}

	@Override
	public FlowDefinitionVo toVO(FlowDefinition e) {
		return converter.map(e, FlowDefinitionVo.class);
	}

	@Override
	public List<FlowDefinitionVo> toVO(List<FlowDefinition> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, FlowDefinitionVo.class))
		        .collect(Collectors.toList());	
	}

	@Override
	public FlowDefinition toEntity(FlowDefinitionDto d) {
		return converter.map(d, FlowDefinition.class);
	}

	@Override
	public List<FlowDefinition> toEntity(List<FlowDefinitionDto> ds) {
		return Optional.ofNullable(ds)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, FlowDefinition.class))
		        .collect(Collectors.toList());	
	}

}
